home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / change3g / form1.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  1999-08-07  |  5.1 KB  |  161 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Define areas in a PictureBox and know if the user clicked there"
  5.    ClientHeight    =   4800
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5400
  9.    MaxButton       =   0   'False
  10.    MinButton       =   0   'False
  11.    ScaleHeight     =   4800
  12.    ScaleWidth      =   5400
  13.    ShowInTaskbar   =   0   'False
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.CommandButton Command2 
  16.       Caption         =   "Hide areas"
  17.       Height          =   345
  18.       Left            =   2730
  19.       TabIndex        =   2
  20.       Top             =   3990
  21.       Width           =   1485
  22.    End
  23.    Begin VB.CommandButton Command1 
  24.       Caption         =   "Show areas"
  25.       Height          =   345
  26.       Left            =   1155
  27.       TabIndex        =   1
  28.       Top             =   3990
  29.       Width           =   1485
  30.    End
  31.    Begin VB.PictureBox Pic 
  32.       AutoRedraw      =   -1  'True
  33.       Height          =   2850
  34.       Left            =   210
  35.       ScaleHeight     =   2790
  36.       ScaleWidth      =   4995
  37.       TabIndex        =   0
  38.       Top             =   1050
  39.       Width           =   5055
  40.    End
  41.    Begin VB.Label Label3 
  42.       AutoSize        =   -1  'True
  43.       Caption         =   "Source code written by Damian Janowski - jano@sinectis.com"
  44.       BeginProperty Font 
  45.          Name            =   "Tahoma"
  46.          Size            =   8.25
  47.          Charset         =   0
  48.          Weight          =   700
  49.          Underline       =   0   'False
  50.          Italic          =   0   'False
  51.          Strikethrough   =   0   'False
  52.       EndProperty
  53.       Height          =   195
  54.       Left            =   105
  55.       TabIndex        =   5
  56.       Top             =   4515
  57.       Width           =   5205
  58.    End
  59.    Begin VB.Label Label2 
  60.       Alignment       =   2  'Center
  61.       Caption         =   "Click on the PictureBox and see what happens..."
  62.       Height          =   225
  63.       Left            =   210
  64.       TabIndex        =   4
  65.       Top             =   630
  66.       Width           =   5055
  67.    End
  68.    Begin VB.Label Label1 
  69.       Alignment       =   2  'Center
  70.       Caption         =   "Define areas in a PictureBox and know if the user clicked there"
  71.       BeginProperty Font 
  72.          Name            =   "Arial"
  73.          Size            =   8.25
  74.          Charset         =   0
  75.          Weight          =   700
  76.          Underline       =   0   'False
  77.          Italic          =   0   'False
  78.          Strikethrough   =   0   'False
  79.       EndProperty
  80.       Height          =   510
  81.       Left            =   210
  82.       TabIndex        =   3
  83.       Top             =   105
  84.       Width           =   5085
  85.    End
  86. Attribute VB_Name = "Form1"
  87. Attribute VB_GlobalNameSpace = False
  88. Attribute VB_Creatable = False
  89. Attribute VB_PredeclaredId = True
  90. Attribute VB_Exposed = False
  91. Option Explicit
  92. Private Type AREA
  93.     Left As Integer
  94.     Top As Integer
  95.     Width As Integer
  96.     Height As Integer
  97. End Type
  98. Const NUM_AREAS = 2 'the number of areas you want to use
  99.                     ' - 1, because the zero is included
  100. Dim Ar(NUM_AREAS) As AREA
  101. Dim CurArea As Integer
  102. Function DefineArea(AreaNumber As Integer, iLeft As Integer, iTop As Integer, iWidth As Integer, iHeight As Integer)
  103.     'Don't forget that the zero IS included!
  104.     With Ar(AreaNumber)
  105.         .Left = iLeft
  106.         .Top = iTop
  107.         .Width = iWidth
  108.         .Height = iHeight
  109.     End With
  110. End Function
  111. Function UserClickedArea(X As Integer, Y As Integer) As Boolean
  112.     Dim I As Integer
  113.     For I = 0 To NUM_AREAS
  114.         With Ar(I)
  115.             If X >= .Left And X <= .Left + .Width And _
  116.                 Y >= .Top And Y <= .Top + .Height Then
  117.                     UserClickedArea = True
  118.                     CurArea = I
  119.                     Exit For
  120.             Else
  121.                 CurArea = -1
  122.             End If
  123.         End With
  124.     Next
  125. End Function
  126. Private Sub Command1_Click()
  127.     DrawAreas Pic
  128. End Sub
  129. Private Sub Command2_Click()
  130.     Pic.Cls
  131. End Sub
  132. Private Sub Form_Load()
  133.     ' This will define 3 areas
  134.     Dim I As Integer
  135.     For I = 0 To NUM_AREAS
  136.         With Ar(I)
  137.             .Left = I * (Pic.ScaleWidth / 3)
  138.             .Top = I * (Pic.ScaleHeight / 3)
  139.             .Width = Pic.ScaleWidth / 3
  140.             .Height = Pic.ScaleHeight / 3
  141.         End With
  142.     Next
  143. End Sub
  144. Private Sub Pic_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  145.     ' The function sets CurArea to the area number
  146.     ' clicked
  147.     ' Else, CurArea = -1
  148.     If UserClickedArea(CInt(X), CInt(Y)) Then MsgBox "You clicked the area number " & CurArea
  149. End Sub
  150. Function DrawAreas(C As Control)
  151.     Dim I As Integer
  152.     For I = 0 To NUM_AREAS
  153.         With Ar(I)
  154.             C.Line (.Left, .Top)-(.Left, .Top + .Height)
  155.             C.Line (.Left, .Top)-(.Left + .Width, .Top)
  156.             C.Line (.Left + .Width, .Top)-(.Left + .Width, .Top + .Height)
  157.             C.Line (.Left, .Top + .Height)-(.Left + .Width, .Top + .Height)
  158.         End With
  159.     Next
  160. End Function
  161.